﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;

namespace Copy4Backup
{
	/// <summary>
	/// Holds project data.
	/// </summary>
	public class Project
	{
		#region Fields

		private List<String> sourceFolders_;

		private List<String> fileFilters_;

		private List<String> folderFilters_;
		#endregion Fields

		#region Properties

		/// <summary>
		/// Gets or sets the project name.
		/// </summary>
		public String Name
		{
			get;
			set;
		}

		/// <summary>
		/// Gets the source folder list.
		/// </summary>
		public ReadOnlyCollection<String> SourceFolders
		{
			get
			{
				return new ReadOnlyCollection<string>(sourceFolders_);
			}
		}

		/// <summary>
		/// Gets or sets the destination folder.
		/// </summary>
		public String DestinationFolder
		{
			get;
			set;
		}

		/// <summary>
		/// Gets the folder filter list.
		/// </summary>
		public ReadOnlyCollection<String> FolderFilters
		{
			get
			{
				return new ReadOnlyCollection<String>(this.folderFilters_);
			}
		}

		/// <summary>
		/// Gets the file filter list.
		/// </summary>
		public ReadOnlyCollection<String> FileFilters
		{
			get
			{
				return new ReadOnlyCollection<String>(this.fileFilters_);
			}
		}
		#endregion Properties

		#region Methods

		/// <summary>
		/// Initializes a new instance of the Project class.
		/// </summary>
		public Project()
		{
			Name = String.Empty;
			sourceFolders_ = new List<string>();
			folderFilters_ = new List<string>();
			fileFilters_ = new List<string>();
			DestinationFolder = String.Empty;
		}

		/// <summary>
		/// Adds a source folder.
		/// </summary>
		/// <param name="folder">The source folder.</param>
		public void AddSourceFolder(String folder)
		{
			if (null != folder && !SourceFolders.Contains(folder))
			{
				sourceFolders_.Add(folder);
			}
		}

		/// <summary>
		/// Clears the source folder list.
		/// </summary>
		public void ClearSourceFolders()
		{
			sourceFolders_.Clear();
		}

		/// <summary>
		/// Adds a folder filter pattern.
		/// </summary>
		/// <param name="folderFilterPattern">The folder filter pattern.</param>
		public void AddFolderFilter(String folderFilterPattern)
		{
			if (null != folderFilterPattern && !FolderFilters.Contains(folderFilterPattern))
			{
				folderFilters_.Add(folderFilterPattern);
			}
		}

		public void ClearFolderFilters()
		{
			folderFilters_.Clear();
		}

		/// <summary>
		/// Adds a file filter pattern (extention).
		/// </summary>
		/// <param name="fileFilterPattern">The file filter pattern (extention).</param>
		public void AddFileFilter(String fileFilterPattern)
		{
			if (null != fileFilterPattern && !FileFilters.Contains(fileFilterPattern))
			{
				fileFilters_.Add(fileFilterPattern);
			}
		}

		/// <summary>
		/// Clears the file filter list.
		/// </summary>
		public void ClearFileFilters()
		{
			fileFilters_.Clear();
		}

		/// <summary>
		/// Gets the object text representation.
		/// </summary>
		/// <returns>The object text representation.</returns>
		public override string ToString()
		{
			StringBuilder sb = new StringBuilder("Project:");
			sb.AppendFormat(" Name: {0}", Name.ToString());

			sb.Append(", SourceFolders: [");
			bool firstTime = true;
			foreach (String sourceFolder in SourceFolders)
			{
				if (firstTime)
				{
					sb.Append(sourceFolder);
					firstTime = false;
				}
				else
				{
					sb.AppendFormat(", {0}", sourceFolder);
				}

			}
			sb.Append("]");

			sb.AppendFormat(", DestinationFolder: {0}", DestinationFolder);


			sb.Append(", Filters: ");
			sb.Append(" FolderFilters: [");
			firstTime = true;
			foreach (String folderFilter in FolderFilters)
			{
				if (firstTime)
				{
					sb.Append(folderFilter);
					firstTime = false;
				}
				else
				{
					sb.AppendFormat(", {0}", folderFilter);
				}

			}
			sb.Append("]");
			sb.Append(", FileFilters: [");
			firstTime = true;
			foreach (String fileFilter in FileFilters)
			{
				if (firstTime)
				{
					sb.Append(fileFilter);
					firstTime = false;
				}
				else
				{
					sb.AppendFormat(", {0}", fileFilter);
				}

			}
			sb.Append("]");

			return sb.ToString();
		}
		#endregion Methods
	}
}
